package com.dididoctor.doctor.Activity.Usercentre.InviteFriend;

import android.content.Intent;
import android.graphics.BitmapFactory;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.dididoctor.doctor.MV.EduActivity;
import com.dididoctor.doctor.R;
import com.umeng.socialize.PlatformConfig;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;

/**
 * Created by liying on 2016/4/22.
 */
public class InviteFriendActivity extends EduActivity implements UMShareListener{
    private LinearLayout mLayWx, mLayWxCircle, mLayQq, mLayQqZone;
    private UMShareAPI mShareApi;
    @Override
    public void init() {

        initView();

    }

    @Override
    public void onClickEvent(View view) {
        UMImage image = new UMImage(InviteFriendActivity.this,
                BitmapFactory.decodeResource(getResources(), R.drawable.applogos));
        switch (view.getId()){
            case R.id.lay_wx:
                new ShareAction(this)
                        .setPlatform(SHARE_MEDIA.WEIXIN)
                        .setCallback(this)
                        .withText("滴滴医生治病赚钱两不误，快去下载吧")
                        .withTargetUrl("http://app2.doudoutech.com/view/share-page.html")
                        .withMedia(image)
                        .share();

                break;
            case R.id.lay_wx_circle:
                new ShareAction(this)
                        .setPlatform(SHARE_MEDIA.WEIXIN_CIRCLE)
                        .setCallback(this)
                        .withText("滴滴医生治病赚钱两不误，快去下载吧")
                        .withTargetUrl("http://app2.doudoutech.com/view/share-page.html")
                        .withMedia(image)
                        .share();
                break;
            case R.id.lay_qq:
                new ShareAction(this)
                        .setPlatform(SHARE_MEDIA.QQ)
                        .setCallback(this)
                        .withText("滴滴医生治病赚钱两不误，快去下载吧")
                        .withTargetUrl("http://app2.doudoutech.com/view/share-page.html")
                        .withMedia(image)
                        .share();
                break;
            case R.id.lay_qq_zone:
                new ShareAction(this)
                        .setPlatform(SHARE_MEDIA.QZONE)
                        .setCallback(this)
                        .withText("滴滴医生治病赚钱两不误，快去下载吧")
                        .withTargetUrl("http://app2.doudoutech.com/view/share-page.html")
                        .withMedia(image)
                        .share();
                break;
        }
    }

    @Override
    public void setContentLayout() {
        setContentView(R.layout.activity_invitefriend);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get( this ).onActivityResult(requestCode, resultCode, data);
//        mShareApi.onActivityResult(requestCode, resultCode, data);
    }


    public void initView() {

        PlatformConfig.setWeixin("wx05cd4ab4bc7bed2e", "69bfcc23c824e977ba1823bc9c2d9a83");
        PlatformConfig.setQQZone("1105281003","XAP7eVC6XWGVHbSs");
//        mShareApi = UMShareAPI.get(this);
//        SHARE_MEDIA platform = SHARE_MEDIA.WEIXIN;
//        mShareApi.doOauthVerify(this, platform, umAuthListener);
//        SHARE_MEDIA platFormQQ = SHARE_MEDIA.QQ;
//        mShareApi.doOauthVerify(this,platFormQQ,umAuthListener);


        ((TextView) findViewById(R.id.tv_title)).setText("邀请好友");
        mLayWx = (LinearLayout) findViewById(R.id.lay_wx);
        mLayWx.setOnClickListener(this);
        mLayWxCircle = (LinearLayout) findViewById(R.id.lay_wx_circle);
        mLayWxCircle.setOnClickListener(this);
        mLayQq = (LinearLayout) findViewById(R.id.lay_qq);
        mLayQq.setOnClickListener(this);
        mLayQqZone = (LinearLayout) findViewById(R.id.lay_qq_zone);
        mLayQqZone.setOnClickListener(this);
    }

    @Override
    public void onResult(SHARE_MEDIA share_media) {
        Toast.makeText(getApplication(),share_media+"分享成功",Toast.LENGTH_SHORT);
    }

    @Override
    public void onError(SHARE_MEDIA share_media, Throwable throwable) {
        Toast.makeText(getApplication(),share_media+"分享失败",Toast.LENGTH_SHORT);
    }

    @Override
    public void onCancel(SHARE_MEDIA share_media) {
        Toast.makeText(getApplication(),share_media+"分享取消",Toast.LENGTH_SHORT);
    }
}
